package com.lancoo.znbkxx.teacher.ui.adapter

import android.content.Context
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.ClassVocabularyMasterDistribInfor
import kotlinx.android.synthetic.main.aibk_adapter_item_project_distribution.view.*

/*
* 学生词汇量掌握情况
* */
class AibkVocabularyMasterStuIntervalAdapter(
        val context: Context?,
        val classVocabularyMasterDistribInfor: ClassVocabularyMasterDistribInfor
): KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(context)
                .inflate(R.layout.aibk_adapter_item_project_distribution, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {
        if(position == 0){
            holder.convertView.TvProjectChange.setCompoundDrawables(null, null, null, null)
            holder.convertView.TvProject.text = "词汇量"
            holder.convertView.TvProjectChange.text = "词汇量较上周变化"
            holder.convertView.IvCheckArrow.visibility = View.INVISIBLE
        }else{
            val stuName = classVocabularyMasterDistribInfor.ClassVocabTable[position-1].StuName
            val stuID = classVocabularyMasterDistribInfor.ClassVocabTable[position-1].StuID
            val vocabNum = classVocabularyMasterDistribInfor.ClassVocabTable[position-1].VocabNum
            var vocabNumChange = classVocabularyMasterDistribInfor.ClassVocabTable[position-1].VocabNumChange

            holder.convertView.TvStuName.text = stuName
            holder.convertView.TvStuID.text = stuID
            holder.convertView.TvProject.text = vocabNum.toString()
            if(vocabNumChange>0){
                holder.convertView.TvProjectChange.text= "+ "+ Math.abs(vocabNumChange)
            }else if(vocabNumChange == 0){
                holder.convertView.TvProjectChange.text= "  "+ Math.abs(vocabNumChange)
            }else{
                holder.convertView.TvProjectChange.text= "- "+ Math.abs(vocabNumChange)
            }

            holder.convertView.TvStuName.setTextColor(context!!.resources.getColor(R.color.textColor2))
            holder.convertView.TvStuID.setTextColor(context!!.resources.getColor(R.color.textColor2))
            holder.convertView.TvProject.setTextColor(context!!.resources.getColor(R.color.textColor2))
            holder.convertView.TvProjectChange.setTextColor(context!!.resources.getColor(R.color.textColor2))

            var drawable: Drawable? = null
            if(vocabNumChange>0) {
                drawable = context.resources.getDrawable(R.mipmap.aibk_icon_score_up)
                drawable.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
            }else if(vocabNumChange==0) {
                drawable = null
            }else{
                drawable = context.resources.getDrawable(R.mipmap.aibk_icon_score_down)
                drawable.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
            }

            holder.convertView.TvProjectChange.setCompoundDrawables(null, null, drawable, null)
            holder.convertView.IvCheckArrow.visibility = View.VISIBLE
            holder.convertView.LlStuDiagnosisInforView.setOnClickListener {
                clickListener!!.onClick(position)
            }
        }
    }

    override fun getItemCount(): Int {
        val classScoreChangeSize = classVocabularyMasterDistribInfor.ClassVocabTable.size
        return classScoreChangeSize+1
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    interface OnClickListener {
        fun onClick(pos:Int)
    }

    private var clickListener: OnClickListener? = null

    fun setClickListener(clickListener: OnClickListener?) {
        this.clickListener = clickListener
    }

}